// SysIconUtils.h

#ifndef __SYS_ICON_UTILS_H
#define __SYS_ICON_UTILS_H

#include <set>

namespace Common
{
namespace FileSystem
{

struct CExtIconPair
{
	CString       Ext;
	int           IconIndex;
	CString       TypeName;
	CExtIconPair() {}
	CExtIconPair(const CExtIconPair &obj) :
		Ext(obj.Ext),
		IconIndex(obj.IconIndex),
		TypeName(obj.TypeName)
	{
	}
};

struct CAttribIconPair
{
	DWORD     Attrib;
	int       IconIndex;
	CString   TypeName;
	CAttribIconPair() {}
	CAttribIconPair(const CAttribIconPair &obj) :
		Attrib(obj.Attrib),
		IconIndex(obj.IconIndex),
		TypeName(obj.TypeName)
	{
	}
};

inline bool operator==(const CExtIconPair &a1, const CExtIconPair &a2)
{
	return a1.Ext == a2.Ext;
}
inline bool operator< (const CExtIconPair &a1, const CExtIconPair &a2)
{
	return a1.Ext < a2.Ext;
}

inline bool operator==(const CAttribIconPair &a1, const CAttribIconPair &a2)
{
	return a1.Attrib == a2.Attrib;
}
inline bool operator< (const CAttribIconPair &a1, const CAttribIconPair &a2)
{
	return a1.Attrib < a2.Attrib;
}

class CExtToIconMap
{
	typedef std::set<CExtIconPair> ArrayExtIconPair;
	typedef std::set<CAttribIconPair> ArrayAttribIconPair;
	ArrayExtIconPair _extMap;
	ArrayAttribIconPair _attribMap;
public:
	void Clear()
	{
		_extMap.clear();
		_attribMap.clear();
	}
	size_t GetIconIndex(DWORD attrib, const CString &fileName, CString &typeName);
	size_t GetIconIndex(DWORD attrib, const CString &fileName);
};

DWORD_PTR GetRealIconIndex(LPCTSTR path, DWORD attrib, int &iconIndex);

int GetIconIndexForCSIDL(int csidl);

inline HIMAGELIST GetSysImageList(bool smallIcons)
{
	SHFILEINFO shellInfo;
	return (HIMAGELIST)SHGetFileInfo(_T(""),
									 FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY,
									 &shellInfo, sizeof(shellInfo),
									 SHGFI_USEFILEATTRIBUTES | SHGFI_SYSICONINDEX | (smallIcons ? SHGFI_SMALLICON : SHGFI_ICON));
}

//Moved from RootFolder.h
CString RootFolder_GetName_Computer(int &iconIndex);
CString RootFolder_GetName_Network(int &iconIndex);
CString RootFolder_GetName_Documents(int &iconIndex);

}
}

#endif
